
function printMatrix(data) {
    if (!data) {
      return;
    }
  
    for (var i = 0, len = data.length; i < len; i++) {
      var row = data[i];
      var rowLog = "";
      for (var j = 0, jLen = row.length; j < jLen; j++) {
        rowLog += (row[j] + "").padStart(5, " ");
      }
      if (i < data.length - 1) {
        rowLog += "\n";
      }
      console.log(rowLog);
    }
  }
  
  function MatrixMultiply(A, B) {
    // console.log(A, B, !(A && A[0] && B && B[0]) )
    if (!(A && A[0] && B && B[0] && A[0].length == B.length)) {
      console.error("两个参数不合法，请保证 两个矩阵合法！");
      return;
    }
    var n = A.length;
    var m = B[0].length;
    var C = [];
    for (var i = 0; i < n; i++) {
      C[i] = [];
      for (var j = 0; j < m; j++) {
        C[i][j] = 0;
        for (var k = 0; k < m; k++) {
          C[i][j] += (A[i][k] || 0) * (B[k][j] || 0);
        }
      }
    }
    return C;
  }
  
  var A = [
    [1, 1, 11],
    // [1, 1, 1, 1]
  ];
  
  var B = [
    [1, 1, 1, 1],
    [2, 1, 1, 1],
    [3, 1, 1, 1],
    [4, 1, 1, 1],
  ];
  
  var C = MatrixMultiply(A, B);

  console.log("");
  printMatrix(A);
  console.log("*");
  console.log("");
  printMatrix(B);
  console.log("=");
  printMatrix(C);
  